package org.alis.rpc.common.protocol;

import com.alibaba.fastjson.JSON;
import lombok.Data;
import org.apache.commons.lang3.StringUtils;

import java.io.Serializable;
import java.util.Objects;

/**
 * RpcServiceInfo desc:
 *
 * @author luochuan
 * @date 2020/9/21
 */
@Data
public class RpcServiceInfo implements Serializable {

    /**
     * 服务名称
     */
    private String serviceName;

    /**
     * 版本号
     */
    private String version;

    @Override
    public boolean equals(Object obj) {
        if (this == obj) {
            return true;
        }
        if (Objects.isNull(obj) || getClass() != obj.getClass()) {
            return false;
        }
        RpcServiceInfo that = (RpcServiceInfo) obj;
        return StringUtils.equals(serviceName, that.serviceName) &&StringUtils.equals(version, that.version);
    }

    @Override
    public int hashCode() {
        return Objects.hash(serviceName, version);
    }

    public String toJson(){
        return JSON.toJSONString(this);
    }

    @Override
    public String toString() {
        return toJson();
    }


}
